﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace PankowGame13
{
    class TreasureTile:Tile
    {
        public bool isTreasure { get; set; }
        public bool isLoot { get; set; }
        public bool isHidden { get; set; }
        public Item lootItem { get; set; }
        public int treasureFindPercentage { get; set; }

        public List<string> helms { get; set; }
        public List<string> armors { get; set; }
        public List<string> legs { get; set; }
        public List<string> boots { get; set; }
        public List<string> weapons { get; set; }
        public List<string> shields { get; set; }
        public List<string> rings { get; set; }
        public List<string> necklaces { get; set; }

        private int _treasureAmount;
        public int treasureAmount 
        {
            get 
            { 
                int tAmt = _treasureAmount; 
                _treasureAmount = 0; 
                return tAmt; 
            }

        }

        public TreasureTile(string treasureTilePicture, Vector2 treasureLocation, int textureSize, string type, int level, bool hidden, ContentManager content, int treasureFind,
            List<string> helmItems, List<string> armorItems, List<string> legItems,
            List<string> bootItems, List<string> weaponItems, List<string> shieldItems,
            List<string> ringItems, List<string> necklaceItems)
        {
            isHidden = hidden;
            isOpen = false;
            if (type == "T")
            {
                isTreasure = true;
            }
            else
            {
                isLoot = true;
            }

            tileTexture = content.Load<Texture2D>(treasureTilePicture);
            tileLocation = treasureLocation;
            tileSize = textureSize;
            canPass = true;
            tileRect = new Rectangle((int)tileLocation.X, (int)tileLocation.Y, textureSize, textureSize);

            helms = helmItems;
            armors = armorItems;
            legs = legItems;
            boots = bootItems;
            weapons = weaponItems;
            shields = shieldItems;
            rings = ringItems;
            necklaces = necklaceItems;

            treasureFindPercentage = treasureFind;

            System.Threading.Thread.Sleep(200);

            FillTreasureChest(content, level);
        }

        public void FillTreasureChest(ContentManager content, int level)
        {
            Random rand = new Random();

            if (isTreasure)
            {
                _treasureAmount = (rand.Next(1 + level, 5 + level) + level) * (2 + treasureFindPercentage);
                if (level > 5 && level < 10)
                {
                    _treasureAmount *= 2;
                }
                if (level >= 10 && level < 20)
                {
                    _treasureAmount *= 3;
                }
                if (level >= 20 && level < 30)
                {
                    _treasureAmount *= 4;
                }
                if (level >= 30 && level < 40)
                {
                    _treasureAmount *= 8;
                }
                if (level >= 40 && level < 50)
                {
                    _treasureAmount *= 16;
                }
                if (level >= 50)
                {
                    _treasureAmount *= 32;
                }
            }
            if (isLoot)
            {
                    lootItem = new Item(level, content, treasureFindPercentage, false, helms, armors, legs,
                        boots, weapons, shields, rings, necklaces);
            }
            

        }
        public void Update(ContentManager content)
        {
            if (!isHidden)
            {
                tileTexture = content.Load<Texture2D>(@"Loot Chest");
            }
            if (isOpen)
            {
                tileTexture = content.Load<Texture2D>(@"Treasure Chest");
            }
        }
    }
}
